/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ca.trader.utils;

/**
 * Utility functions for strings
 *
 * @author Ahsan
 */
public class TraderStringUtils
{

	 /**
	  * Trims a string to a certain length. If the string's length is <= to
	  * than the required length, the original string is returned. If the
	  * string's length is > than the required length, the string is trimmed to
	  * that length via substring
	  *
	  * @param string the string
	  * @param lengthToTrimTo the length to trim to
	  * @return the trimmed string
	  */
	 public static String trimStringToLength(String string, int lengthToTrimTo)
	 {
		  if (string.length() <= lengthToTrimTo)
		  {
			   return string;
		  }

		  return string.substring(0, lengthToTrimTo);
	 }

	 public static String newlineToBr(String string)
	 {
		  string = string.replaceAll("\\r?\\n", "<br />");
		  string = string.replace("  ", " &emsp;");

		  return string;
	 }

}
